//
//  CashierTableViewCell.m
//  chongwu
//
//  Created by 隼目 on 2021/9/17.
//

#import "CashierTableViewCell.h"

@implementation CashierTableViewCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}
-(void)creatView{
    self.backgroundColor=[UIColor whiteColor];
    
    UILabel *moneyLabel=[UILabel new];
    [self.contentView addSubview:moneyLabel];
    [moneyLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(0);
        make.top.mas_equalTo(125*_mainHeight);
    }];
    NSString *titleStr=[NSString stringWithFormat:@"¥%@",@"236.00"];
    NSMutableAttributedString *titleAttri =  [[NSMutableAttributedString alloc] initWithString:titleStr];
    NSRange priceRange = [titleStr rangeOfString:[NSString stringWithFormat:@"¥"]];//匹配得到的下标
    NSRange priceRange2 = [titleStr rangeOfString:[NSString stringWithFormat:@"%@",@"236.00"]];//匹配得到的下标
    [titleAttri addAttribute:NSFontAttributeName value:[UIFont fontWithName:@"Helvetica-BoldOblique" size:autoScaleW(55)] range:priceRange];
    [titleAttri addAttribute:NSForegroundColorAttributeName value:rgba(44,46,52,1) range:priceRange];
    [titleAttri addAttribute:NSFontAttributeName value:[UIFont fontWithName:@"Helvetica-BoldOblique" size:autoScaleW(77)] range:priceRange2];
    [titleAttri addAttribute:NSForegroundColorAttributeName value:rgba(44,46,52,1) range:priceRange2];
    moneyLabel.attributedText=titleAttri;
    
    UIImageView *moneyImage=[UIImageView new];
    [self.contentView addSubview:moneyImage];
    [moneyImage mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(0);
        make.top.mas_equalTo(moneyLabel.mas_bottom).mas_equalTo(16*_mainHeight);
        make.width.mas_equalTo(157*_mainWidth);
        make.height.mas_equalTo(14*_mainWidth);
    }];
    moneyImage.image=[UIImage imageNamed:@"shuziyinyng"];
    
    UIView *centreView=[UIView new];
    [self.contentView addSubview:centreView];
    [centreView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(40*_mainWidth);
        make.right.mas_equalTo(-40*_mainWidth);
        make.top.mas_equalTo(moneyImage.mas_bottom).mas_equalTo(93*_mainHeight);
        make.height.mas_equalTo(309*_mainHeight);
    }];
    centreView.backgroundColor=rgba(248,248,247,1);
    centreView.layer.masksToBounds=YES;
    centreView.layer.cornerRadius=25*_mainWidth;
    
    UIView *xianView=[UIView new];
    [centreView addSubview:xianView];
    [xianView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(20*_mainWidth);
        make.right.mas_equalTo(-3*_mainWidth);
        make.height.mas_equalTo(1*_mainHeight);
        make.centerY.mas_equalTo(0);
    }];
    xianView.backgroundColor=rgba(232,232,232,1);
    
    UIView *wxView=[UIView new];
    [centreView addSubview:wxView];
    [wxView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.top.mas_equalTo(0);
        make.bottom.mas_equalTo(xianView.mas_top);
    }];
    
    UIImageView *wximage=[UIImageView new];
    [wxView addSubview:wximage];
    [wximage mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(0);
        make.left.mas_equalTo(58*_mainWidth);
        make.height.width.mas_equalTo(54*_mainWidth);
    }];
    wximage.image=[UIImage imageNamed:@"weixin"];
    
    UILabel *wxLabel=[UILabel new];
    [wxView addSubview:wxLabel];
    [wxLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(0);
        make.left.mas_equalTo(wximage.mas_right).mas_equalTo(36*_mainWidth);
    }];
    wxLabel.text=@"微信";
    wxLabel.textColor=rgba(44,46,52,1);
    wxLabel.font=[UIFont fontWithName:@"PingFang SC" size:autoScaleW(30)];
    
    
    UIButton *selectBtn=[UIButton new];
    [wxView addSubview:selectBtn];
    [selectBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(-61*_mainWidth);
        make.centerY.mas_equalTo(0);
        make.width.height.mas_equalTo(45*_mainWidth);
    }];
    selectBtn.tag=1;
    if (!self.isZFB) {
        [selectBtn setImage:[UIImage imageNamed:@"xuanzhong-1"] forState:0];
    }else{
        [selectBtn setImage:[UIImage imageNamed:@"weixuanzhong-1"] forState:0];
    }
    [selectBtn addTarget:self action:@selector(selectWXOrZFBBtn:) forControlEvents:UIControlEventTouchUpInside];
    
    
    UIView *ZFBView=[UIView new];
    [centreView addSubview:ZFBView];
    [ZFBView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.bottom.mas_equalTo(0);
        make.top.mas_equalTo(xianView.mas_bottom);
    }];
    
    UIImageView *zfbimage=[UIImageView new];
    [ZFBView addSubview:zfbimage];
    [zfbimage mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(0);
        make.left.mas_equalTo(58*_mainWidth);
        make.height.width.mas_equalTo(54*_mainWidth);
    }];
    zfbimage.image=[UIImage imageNamed:@"zhifubao"];
    
    UILabel *zfbLabel=[UILabel new];
    [ZFBView addSubview:zfbLabel];
    [zfbLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(0);
        make.left.mas_equalTo(wximage.mas_right).mas_equalTo(36*_mainWidth);
    }];
    zfbLabel.text=@"支付宝";
    zfbLabel.textColor=rgba(44,46,52,1);
    zfbLabel.font=[UIFont fontWithName:@"PingFang SC" size:autoScaleW(30)];
    
    
    UIButton *selectBtn2=[UIButton new];
    [ZFBView addSubview:selectBtn2];
    [selectBtn2 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(-61*_mainWidth);
        make.centerY.mas_equalTo(0);
        make.width.height.mas_equalTo(45*_mainWidth);
    }];
    selectBtn2.tag=2;
    if (self.isZFB) {
        [selectBtn2 setImage:[UIImage imageNamed:@"xuanzhong-1"] forState:0];
    }else{
        [selectBtn2 setImage:[UIImage imageNamed:@"weixuanzhong-1"] forState:0];
    }
    [selectBtn2 addTarget:self action:@selector(selectWXOrZFBBtn:) forControlEvents:UIControlEventTouchUpInside];
    
    UIButton *submitBtn=[UIButton new];
    [self.contentView addSubview:submitBtn];
    [submitBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(39*_mainWidth);
        make.width.mas_equalTo(_mainW-78*_mainWidth);
        make.top.mas_equalTo(centreView.mas_bottom).mas_equalTo(60*_mainHeight);
        make.height.mas_equalTo(_mainHeight*87);
    }];
    [submitBtn setTitle:@"立即支付" forState:0];
    [submitBtn setTitleColor:[UIColor whiteColor] forState:0];
    submitBtn.titleLabel.font=[UIFont fontWithName:@"PingFang SC" size:autoScaleW(36)];
    
    [submitBtn layoutIfNeeded];
    submitBtn.layer.masksToBounds=YES;
    submitBtn.layer.cornerRadius=87*_mainHeight/2;
    CAGradientLayer *gradientLayer = [CAGradientLayer layer];
    gradientLayer.frame = submitBtn.bounds;
    //将CAGradientlayer对象添加在我们要设置背景色的视图的layer层
    [submitBtn.layer insertSublayer:gradientLayer atIndex:0];
    //设置渐变区域的起始和终止位置（范围为0-1）
    gradientLayer.startPoint = CGPointMake(0, 1);
    gradientLayer.endPoint = CGPointMake(1, 1);
    gradientLayer.colors = @[(__bridge id)rgba(255,159,0,1).CGColor,
                             (__bridge id)rgba(255,116,0,1).CGColor ,
                             (__bridge id)rgba(255,102,0,1).CGColor];
    //设置颜色分割点（范围：0-1）
    gradientLayer.locations = @[@(0),@(0.5), @(1.0f)];
    submitBtn.layer.shadowColor = rgba(196,50,0,0.36).CGColor;
    submitBtn.layer.shadowOffset = CGSizeMake(0,0);
    submitBtn.layer.shadowOpacity = 1;
    submitBtn.layer.shadowRadius = 4;
    [submitBtn addTarget:self action:@selector(selectSubmitBtn) forControlEvents:UIControlEventTouchUpInside];
}

-(void)selectWXOrZFBBtn:(UIButton *)btn{
    if (self.delegate!=nil) {
        [self.delegate selectWXOrZFB:btn.tag];
    }
}
-(void)selectSubmitBtn{
    if (self.delegate!=nil) {
        [self.delegate selectSubmit];
    }
}
@end
